<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "mkt_source_service".
 *
 * @property string $id
 * @property string $user_id
 * @property string $service_other
 * @property string $service_device_rent
 * @property string $service_talnet
 * @property string $area_id
 */
class MktSourceService extends \yii\db\ActiveRecord
{
    public $parent_area_id;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'mkt_source_service';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'service_type', 'service_other', 'service_device_rent', 'service_talnet', 'area_id'], 'integer'],
            [['parent_area_id'],'safe']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'service_type' => '服务类型',            
            'service_other' => '各类服务',
            'service_device_rent' => '物料租赁',
            'service_talnet' => '技能人才',
            'area_id' => '服务区域',
        ];
    }

    /**
     * @inheritdoc
     * @return MktSourceServiceQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new MktSourceServiceQuery(get_called_class());
    }

    public function getUser()
    {
        return $this->hasOne(MktUser::className(), ['id' => 'user_id']);
    }

    public function getArea()
    {
        return $this->hasOne(MktArea::className(), ['id' => 'area_id']);
    }

    public function getIndustryPaths()
    {
        return empty($this->industry) ? '' : $this->industry->getPaths();
    }

    public function getAreaPaths()
    {
        return empty($this->area) ? '' : $this->area->getPaths();
    }

    static function getServiceTypeOption($key=null)
    {
        $arr = array(
            0 => '技能人才',
            1 => '物料租赁',
            2 => '各类服务',
        );        
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '');
    }

    
}
